package com.NewsServiceImpl;

import com.NewsDao.NewsDao;
import com.NewsDaoImpl.NewsDaoImpl;
import com.NewsService.NewsService;
import com.entity.News;
import com.entity.NewsDetail;
import com.entity.User;

import java.util.ArrayList;
import java.util.List;

public class NewsServiceImpl implements NewsService  {

    //实例化Dao接口
    private  NewsDao    newsDao = new NewsDaoImpl();

    @Override
    public List<News> ServiceSelectAll() {
        //先查询 Redis缓存数据
       List<News> list= newsDao.selectAll();
        if(list.size()>0){
            return newsDao.selectAll();
        }else {
            //返回空数据
          return  new ArrayList<News>();
        }
    }

    @Override
    public News ServiceSselectById(int id) {

        return newsDao.selectById(id);
    }

    @Override
    public List<News> ServicesSlectPage(int index, int crencount) {



        return newsDao.selectPage(index,crencount);
    }

    @Override
    public User getSeleUser(String name, String password) {
        return  newsDao.getUser(name,password);
    }

    @Override
    public int ServiceSinsertNews(NewsDetail newsDetail) {
        return newsDao.insertNews(newsDetail);
    }

    @Override
    public int ServiceSdeleteById(int id) {
        return newsDao.deleteById(id);
    }

    @Override
    public int ServiceSdeleteByName(String name) {
        return 0;
    }

    @Override
    public int ServiceSupdateById(int id) {
        return 0;
    }

    @Override
    public int ServiceSupdateByByName(String name) {
        return 0;
    }


    @Override
    public int ServiceUpdateNews(News news) {

        return newsDao.updateNews(news);
    }
}
